<?php

/**
 * Created by ymk
 * User: Administrator
 * Date: 2018/6/25
 * Time: 14:58
 */

namespace MeetUp\Model;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;


class TopicComment extends Base
{
    use SoftDeletes;
    protected $table = 'topic_comment';
    protected $primaryKey = 'comment_id';
    protected $fillable = ['topicid','uid','replyid','content'];
    //关联用户users
    public function user(){
        return $this->hasOne('MeetUp\Model\Users','id','comment_id');
    }
    //帖子评论数
    public function number($id){
        return $this->where(['topicid'=>$id])->count();
    }
    //具体帖子的评论
    public function comment($id){
        return $this->where(['topicid'=>$id])
            ->join('users','topic_comment.uid','=','users.id')
            ->get()->toArray();
    }
    //新增帖子评论
    public function add_comment($topid,$uid,$content,$name = '',$replyid = ''){
        $topic = new \MeetUp\Model\TopicComment;
        $topic->topicid = $topid;
        $topic->uid = $uid;
        if((!$name == '') && (!$replyid == '')){
            $topic->reply_name = $name;
            $topic->replyid = $replyid;
        }
        $topic->content = $content;
        return $topic->save();
    }


}